package com.somnus.androidkotlindemo;

import android.app.Application;
import android.content.Intent;

import com.chad.library.adapter.base.BaseViewHolder;
import com.somnus.androidkotlindemo.databinding.DataBindingAdapter;

/**
 * Created by Somnus on 2017/6/14.
 *
 * @Description:
 */

public class AppContext extends Application {


    private AppContext instance;

    @Override
    public void onCreate() {
        super.onCreate();
        instance = this;

//        Thread.setDefaultUncaughtExceptionHandler(restartHandler);


    }


    /***
     * 应用崩溃
     */
    private Thread.UncaughtExceptionHandler restartHandler = new Thread.UncaughtExceptionHandler() {
        @Override
        public void uncaughtException(Thread t, Throwable e) {
            restartApp();
        }
    };

    private void restartApp() {
        Intent mIntent = new Intent(instance, MainActivity.class);
        mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        instance.startActivity(mIntent);
        android.os.Process.killProcess(android.os.Process.myPid());
    }



}
